package com.cooge.sharevideo.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cooge.sharevideo.base.BaseController;
import com.cooge.sharevideo.web.pojo.Menu;
import com.cooge.sharevideo.web.pojo.Video;
import com.cooge.sharevideo.web.service.MenuService;
import com.cooge.sharevideo.web.service.VideoService;
/**
 * 第一网页处理
 * @author 楚平
 *
 */
@Controller
public class MainController extends BaseController{
	
	@Autowired
	MenuService menuService;
	@Autowired
	VideoService videoService;
	
	@RequestMapping(value = "index.html",method=RequestMethod.GET)
	public ModelAndView goLogin(Model model){
		ModelAndView mav=new ModelAndView("index");
		Menu menu = new Menu();
		menu.setParentId(1L);
		List<Menu> list = menuService.getList(menu);
		model.addAttribute("list", list);
		return mav;
	}
	
	@RequestMapping(value = "type_{id}.html",method=RequestMethod.GET)
	public ModelAndView type(Model model,@PathVariable Long id){
		ModelAndView mav=new ModelAndView("type");
		Menu menu  =menuService.getMenuById(id);
		model.addAttribute("menu", menu);
		
		List<Video> vlist  = videoService.getVideoListBymenuId(menu.getId());
		model.addAttribute("vlist", vlist);
		
		return mav;
	}
	
	@RequestMapping(value = "tv.html",method=RequestMethod.GET)
	public ModelAndView tv(Model model){
		
		ModelAndView mav=new ModelAndView("tv");
		return mav;
	}

}
